<?php

class Test_Abovo_DataFilter extends Solar_Test {
    
    private $_filter;
    
    public function setup()
    {
        $this->_filter = Solar::factory('Abovo_DataFilter');
    }
    
    public function testCountry()
    {
        // valid country
        $this->assertTrue($this->_filter->validateCountry('FI'));
        
        // not valid
        $this->assertFalse($this->_filter->validateCountry('AA'));
        
        $this->_filter->setRequire(false);
        // allow blank
        $this->assertSame($this->_filter->validateCountry(''), null);
    }
    
    public function testZip()
    {
        // strings allowed
        $this->assertTrue($this->_filter->validateZip('12345'));

        // valid zip
        $this->assertTrue($this->_filter->validateZip(12345));

        $this->_filter->setRequire(false);
        // invalid zip
        $this->assertSame($this->_filter->validateZip(null), null);
    }
    
    public function testVat()
    {
        // valid vat
        $this->assertTrue($this->_filter->validatevat('FI12345678'));
        
        // not valid
        $this->assertFalse($this->_filter->validatevat('123456789'));
        
        // not valid country
        $this->assertFalse($this->_filter->validatevat('AA12345678'));
        
        // numerical end part not allowed. int(+12345) is a valid numeric value
        $this->assertFalse($this->_filter->validatevat('FI+1234567'));
        
        $this->_filter->setRequire(false);
        // allow blank
        $this->assertSame($this->_filter->validateVat(null), null);
    }
    
    public function testTel()
    {
        $this->assertTrue($this->_filter->validatetel('+358405755645'));
        $this->assertFalse($this->_filter->validatetel('3581234567891'));
        $this->assertFalse($this->_filter->validatetel('+358 1234567891'));
        $this->assertFalse($this->_filter->validatetel('+35812345678911234'));
    }
    
    public function testWikiPage()
    {
        $this->assertTrue($this->_filter->validatewikiPage('Wiki_page'));
        $this->assertTrue($this->_filter->validatewikiPage('1234'));
        $this->assertFalse($this->_filter->validatewikiPage('wiki link'));
        $this->assertFalse($this->_filter->validatewikiPage(' wiki_link'));
    }
}
